package Card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardTest {
    public static final String[] SUITS = {"♠", "♥", "♣", "♦"};

    //定义四个花色
    public static List<Card> setCard() {
        List<Card> cards = new ArrayList<Card>(52);
        //不包含大小王 52张牌
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                //获取一个花色
                Card card = new Card();
                card.value = j;
                card.suit = suit;
                //创建一张牌 将值和花色初始化好
                cards.add(card);
                //将创建好的扑克牌放进牌堆中
            }
        }
        return cards;
    }

    private static void swap(List<Card> cards, int i, int j) {
        Card card = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,card);
    }

    private static void shuffle(List<Card> cards) {
        Random random = new Random(20230409);
        for (int i = 0; i < cards.size(); i++) {
            int r = random.nextInt(52-i);
            //创建一个随机数
            swap(cards,i,r);
        }
    }

    public static void main(String[] args) {
        List<Card> ret = setCard();
        shuffle(ret);
        System.out.println(ret);
    }
}
